Ext.define('SKJF.view.PEMBELIAN.PENDINGORDER', {
	extend: 'Ext.grid.Panel',
	
	requires	: ['Ext.grid.*',
		'Ext.data.*',
		'Ext.form.field.Number',
		'Ext.form.field.Date',
		'Ext.tip.QuickTipManager'],
	
	itemId		: 'PENDINGORDER',
    alias       : 'widget.PENDINGORDER',
    columnLines : true,
    frame		: true,
    margins		: 0,
    
    initComponent: function(){
		var me = this;
		
		var pendingOrder_store = Ext.create('Ext.data.Store', {
			fields: [
                {name: 'NOMOR_LPB', type: 'string', mapping: 'NOMOR_LPB'},
                {name: 'NOMOR_PO', type: 'string', mapping: 'NOMOR_PO'},
                {name: 'NAMA_BARANG', type: 'string', mapping: 'NAMA_BARANG'},
                {name: 'POD_QTY', type: 'number', mapping: 'POD_QTY'},
                {name: 'TBD_QTY', type: 'number', mapping: 'TBD_QTY'},
                {name: 'QUANTITY', type: 'number', mapping: 'QUANTITY'},
                {name: 'HARGA_SATUAN', type: 'number', mapping: 'HARGA_SATUAN'}
            ],
			proxy: {
				type: 'ajax',
				api: {
					read    : 'c_po/getPendingOrder'
					// create	: 'c_mstcustomer/save',
					// update	: 'c_mstcustomer/save',
					// destroy	: 'c_mstcustomer/delete'
				},
				actionMethods: {
					read    : 'POST',
					create	: 'POST',
					update	: 'POST',
					destroy	: 'POST'
				},
				reader: {
					type            : 'json',
					root            : 'data',
					rootProperty    : 'data',
					successProperty : 'success',
					messageProperty : 'message'
				},
				writer: {
					type            : 'json',
					writeAllFields  : true,
					root            : 'data',
					encode          : true
				},
				listeners: {
					exception: function(proxy, response, operation){
						Ext.MessageBox.show({
							title: 'REMOTE EXCEPTION',
							msg: operation.getError(),
							icon: Ext.MessageBox.ERROR,
							buttons: Ext.Msg.OK
						});
					}
				}
			},
			proxy: {
				type: 'ajax',
				url: 'c_po/getPendingOrder',
				reader: {
					type: 'json',
					root: 'data'
				}
			},
			autoLoad : true
		});
		
    	this.store = pendingOrder_store;
		this.plugins=['bufferedrenderer'];
    	this.features = [{
				ftype: 'filters',
				autoReload: true,
				encode: true,
				local: false
			}];	
		this.columns = [
			{
				header: 'NOMOR_LPB',filterable:true,
				dataIndex: 'NOMOR_LPB'
			},{
				header: 'NOMOR_PO',filterable:true,
				dataIndex: 'NOMOR_PO'
			},{
				header: 'NAMA_BARANG',filterable:true,
				dataIndex: 'NAMA_BARANG'
			},{
				header: 'PO_QTY',filterable:true,
				dataIndex: 'POD_QTY'
			},{
				header: 'TRM_QTY',filterable:true,
				dataIndex: 'TBD_QTY'
			},{
				header: 'PENDING_ORDER_QTY',filterable:true,
				dataIndex: 'QUANTITY'
			},{
				header: 'HARGA_SATUAN',filterable:true,
				dataIndex: 'HARGA_SATUAN'
			},{ text: 'HARGA TOTAL', align:'right', style: 'text-align:center',  dataIndex: 'HARGA_TOTAL', filterable: true,
				renderer: function(value, metaData, record, rowIdx, colIdx, store, view) {
					return (record.get('QUANTITY') * record.get('HARGA_SATUAN'));
				}
			}];
        
        this.dockedItems = [
			Ext.create('Ext.toolbar.Toolbar', {
				items: [{
					xtype: 'fieldcontainer',
					layout: 'hbox',
					defaultType: 'button',
					items: [{
						itemId	: 'btnprint',
						text	: 'Cetak',
						iconCls	: 'icon-print',
						action	: 'print',
						handler	: function(){
							Ext.ux.egen.Printer.mainTitle = 'Daftar Pending Order';
							Ext.ux.egen.Printer.printAuto = false;
							Ext.ux.egen.Printer.print(me);
							
							console.info(me);
							//Ext.ux.egen.Printer.generateBody(me);
						}
					}]
				}]
			})
		];        
        this.callParent(arguments);
    }

});